package com.abbas.CayTcore.adapter

import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import androidx.viewbinding.ViewBinding

abstract class BaseAdapter<VH: RecyclerView.ViewHolder,T,VB: ViewBinding>(var data: MutableList<T>) : RecyclerView.Adapter<VH>() {

    protected lateinit var viewBinding: VB

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): VH {
        return initViewHolder(getViewBinding(parent, viewType).also {
            viewBinding = it
        }.root)
    }

    abstract fun getViewBinding(parent: ViewGroup, viewType: Int): VB

    abstract fun initViewHolder(view: View): VH

    override fun getItemCount(): Int {
        return data.size
    }
}